home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / arc / SkBackup11.lha / Skbackup / Sources / SkBackupWin.c < prev   
C/C++ Source or Header  |  1995-01-31  |  14KB  |  500 lines

  1. /*    SkBackup Frontend ©1994 Dario Rosati    */
  2. /*    SkBackup is ©1994 Alessandro Pozzoli    */
  3.  
  4. #include <exec/types.h>
  5. #include <dos/dos.h>
  6. #include <dos/dostags.h>
  7. #include <libraries/asl.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/classes.h>
  10. #include <intuition/classusr.h>
  11. #include <intuition/imageclass.h>
  12. #include <intuition/gadgetclass.h>
  13. #include <libraries/gadtools.h>
  14. #include <graphics/displayinfo.h>
  15. #include <graphics/gfxbase.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/gadtools_protos.h>
  19. #include <clib/graphics_protos.h>
  20. #include <clib/utility_protos.h>
  21. #include <clib/dos_protos.h>
  22. #include <clib/asl_protos.h>
  23. #include <string.h>
  24. #include <stdio.h>
  25.  
  26. #define GetString(g)      (((struct StringInfo *)g->SpecialInfo)->Buffer)
  27. #define GetNumber(g)      (((struct StringInfo *)g->SpecialInfo)->LongInt)
  28.  
  29. #define GD_COmm                                0
  30. #define GD_Delete                              1
  31. #define GD_Recurs                              2
  32. #define GD_Verbose                             3
  33. #define GD_Ask                                 4
  34. #define GD_Size                                5
  35. #define GD_GO                                  6
  36. #define GD_Gadget70                            7
  37. #define    GD_NewAr                   8
  38.  
  39. #define GDX_COmm                               0
  40. #define GDX_Delete                             1
  41. #define GDX_Recurs                             2
  42. #define GDX_Verbose                            3
  43. #define GDX_Ask                                4
  44. #define GDX_Size                               5
  45. #define GDX_GO                                 6
  46. #define GDX_Gadget70                           7
  47. #define GDX_NewAr                   8
  48.  
  49. #define BackupWin_CNT 9
  50.  
  51.  
  52. extern char __stdiowin[]="CON:20/114/600/142/SkandalBackup"; 
  53.  
  54. extern struct IntuitionBase *IntuitionBase;
  55. extern struct Library       *GadToolsBase;
  56. extern struct Library       *DiskFontBase;
  57. extern struct Library        *IconBase;
  58. extern struct Library        *AslBase;
  59. extern struct Library        *DOSBase;
  60.  
  61. int SetupScreen(void);
  62. void CloseDownScreen(void);
  63. void HandleBackupWinIDCMP(void);
  64. int BackupWinCloseWindow();
  65. int BackupWinVanillaKey();
  66. int OpenBackupWinWindow(void);
  67. void CloseBackupWinWindow(void);
  68.  
  69. /*
  70.  *  Source machine generated by GadToolsBox V2.0b
  71.  *  which is (c) Copyright 1991-1993 Jaba Development
  72.  *
  73.  *  GUI Designed by : Xenon
  74.  */
  75.  
  76. struct Screen         *Scr = NULL;
  77. APTR                   VisualInfo = NULL;
  78. UBYTE              *PubScreenName=NULL;
  79. struct Window         *BackupWinWnd = NULL;
  80. struct Gadget         *BackupWinGList = NULL;
  81. struct IntuiMessage    BackupWinMsg;
  82. struct Gadget         *BackupWinGadgets[9];
  83. UWORD                  BackupWinLeft = 98;
  84. UWORD                  BackupWinTop = 11;
  85. UWORD                  BackupWinWidth = 462;
  86. UWORD                  BackupWinHeight = 91;
  87. UBYTE                 *BackupWinWdt = (UBYTE *)"Skandal Backup FrontEnd ©1994 by Dario Rosati";
  88.  
  89. UBYTE *COmm0Labels[] = {
  90.     (UBYTE *)"Add",
  91.     (UBYTE *)"Extract",
  92.     (UBYTE *)"List",
  93.     (UBYTE *)"Statistic",
  94.     NULL };
  95.  
  96. struct TextAttr topaz8 = {
  97.     ( STRPTR )"topaz.font", 8, 0x00, 0x01 };
  98.  
  99. UWORD BackupWinGTypes[] = {
  100.     CYCLE_KIND,
  101.     CHECKBOX_KIND,
  102.     CHECKBOX_KIND,
  103.     CHECKBOX_KIND,
  104.     CHECKBOX_KIND,
  105.     INTEGER_KIND,
  106.     BUTTON_KIND,
  107.     BUTTON_KIND,
  108.     CHECKBOX_KIND
  109. };
  110.  
  111. struct NewGadget BackupWinNGad[] = {
  112.     214, 33, 101, 13, (UBYTE *)"Command", NULL, GD_COmm, PLACETEXT_RIGHT, NULL, NULL,
  113.     18, 6, 26, 11, (UBYTE *)"Delete Files ?", NULL, GD_Delete, PLACETEXT_RIGHT, NULL, NULL,
  114.     18, 20, 26, 11, (UBYTE *)"Recursive Dir ?", NULL, GD_Recurs, PLACETEXT_RIGHT, NULL, NULL,
  115.     18, 35, 26, 11, (UBYTE *)"Verbose ?", NULL, GD_Verbose, PLACETEXT_RIGHT, NULL, NULL,
  116.     18, 50, 26, 11, (UBYTE *)"Ask Disks ?", NULL, GD_Ask, PLACETEXT_RIGHT, NULL, NULL,
  117.     214, 50, 100, 12, (UBYTE *)"Size in Bytes", NULL, GD_Size, PLACETEXT_RIGHT, NULL, NULL,
  118.     17, 71, 95, 12, (UBYTE *)"GO!", NULL, GD_GO, PLACETEXT_IN, NULL, NULL,
  119.     337, 71, 95, 12, (UBYTE *)"About...", NULL, GD_Gadget70, PLACETEXT_IN, NULL, NULL,
  120.     214, 6, 26,11, (UBYTE *)"New Archive ?", NULL, GD_NewAr, PLACETEXT_RIGHT, NULL, NULL
  121. };
  122.  
  123. ULONG BackupWinGTags[] = {
  124.     (GTCY_Labels), (ULONG)&COmm0Labels[0], (GT_Underscore), '_', (TAG_DONE),
  125.     (GT_Underscore), '_', (TAG_DONE),
  126.     (GTCB_Checked), TRUE, (GT_Underscore), '_', (TAG_DONE),
  127.     (GTCB_Checked), TRUE, (GT_Underscore), '_', (TAG_DONE),
  128.     (GTCB_Checked), FALSE, (GT_Underscore), '_', (TAG_DONE),
  129.     (STRINGA_Justification),GACT_STRINGRIGHT,(GTIN_Number), 8900000, (GTIN_MaxChars), 20, (GT_Underscore), '_', (TAG_DONE),
  130.     (TAG_DONE),
  131.     (TAG_DONE),
  132.     (GTCB_Checked), TRUE, (GT_Underscore), '_', (TAG_DONE)
  133. };
  134.  
  135.  
  136. struct TagItem stags[4];
  137.  
  138.  
  139. LONG __OSlibversion = 37;    /* Needed by libraries initilizers */
  140.  
  141. /* Various flags settings */
  142.  
  143. BOOL    FLG_DeleteFiles = FALSE;
  144. BOOL    FLG_Verbose    = TRUE;
  145. BOOL    FLG_AskDisks    = FALSE;
  146. BOOL    FLG_Recursive    = TRUE;
  147. BOOL    FLG_NewArchive    =TRUE;
  148. char    Commands[4]    = {'a','e','l','s'};
  149. UBYTE    ActualCMD    = 0;            /* default action: Add */ 
  150. int    FileSize    = 890000;        /* default size: 880k  */  
  151. char    CMDLine[256];
  152.  
  153. struct    EasyStruct AboutRequest = {
  154.     sizeof(struct EasyStruct),
  155.     0,
  156.     "SkandalBackup",
  157.     "SkandalBackup v1.1 ©1994 by Alessandro Pozzoli (Willow)\n"
  158.     "SkandalBackup Frontend v1.03 by Dario Rosati   (Xenon) \n\n"
  159.     "This program is freeware. Not for commercial use. \n"
  160.     "Be sure to have SkBackup anywhere in your PATH !! \n",
  161.     "Understood"
  162.     };
  163.  
  164. struct    EasyStruct WrongSel = {
  165.     sizeof(struct EasyStruct),
  166.     0,
  167.     "SkandalBackup v1.1",
  168.     "Invalid selection!",
  169.     "Try Again"
  170.     };
  171.     
  172. struct    FileRequester *FileReq;
  173.  
  174. /* Functions calls from here... */
  175.  
  176. int SetupScreen(void)
  177. {
  178.     if (!(Scr = LockPubScreen(NULL)))
  179.         return(1L);
  180.  
  181.     if (!(VisualInfo = GetVisualInfo(Scr, TAG_DONE)))
  182.         return(2L);
  183.  
  184.     return(0L);
  185. }
  186.  
  187. void CloseDownScreen(void)
  188. {
  189.     if (VisualInfo) {
  190.         FreeVisualInfo(VisualInfo);
  191.         VisualInfo = NULL;
  192.     }
  193.  
  194.     if (Scr) {
  195.         UnlockPubScreen(NULL, Scr);
  196.         Scr = NULL;
  197.     }
  198. }
  199.  
  200. void HandleBackupWinIDCMP(void)
  201. {
  202.     struct IntuiMessage    *m;
  203.     BOOL            done = FALSE;
  204.     struct Gadget        *PressedGad;
  205.     BPTR            ExtractDir;
  206.  
  207. while(!done)
  208. {
  209.         Wait(1L << BackupWinWnd->UserPort->mp_SigBit);
  210.     while((m = GT_GetIMsg(BackupWinWnd->UserPort)) && (done==FALSE))
  211.     {
  212.         CopyMem((char *)m,(char *)&BackupWinMsg,(long)sizeof(struct IntuiMessage));
  213.         GT_ReplyIMsg(m);
  214.  
  215.         switch (BackupWinMsg.Class) {
  216.  
  217.             case    IDCMP_REFRESHWINDOW:
  218.                 GT_BeginRefresh(BackupWinWnd);
  219.                 GT_EndRefresh(BackupWinWnd, TRUE);
  220.                 break;
  221.  
  222.             case    IDCMP_CLOSEWINDOW:
  223.                 done=TRUE;
  224.                 break;
  225.  
  226.             case    IDCMP_VANILLAKEY:
  227.                 break;
  228.  
  229.             case    IDCMP_GADGETUP:
  230.                 PressedGad = ((struct Gadget *)m->IAddress);
  231.                 switch (PressedGad->GadgetID)
  232.                 {
  233.                     case GD_COmm:
  234.                     ActualCMD = m->Code;
  235.  
  236.                     switch (ActualCMD)
  237.                     {
  238.                         case 0:    /* Add */
  239.                         GT_SetGadgetAttrs(BackupWinGadgets[1],BackupWinWnd,0,(GA_Disabled),FALSE,(TAG_END));
  240.                         GT_SetGadgetAttrs(BackupWinGadgets[2],BackupWinWnd,0,(GA_Disabled),FALSE,(TAG_END));
  241.                         GT_SetGadgetAttrs(BackupWinGadgets[4],BackupWinWnd,0,(GA_Disabled),FALSE,(TAG_END));
  242.                         GT_SetGadgetAttrs(BackupWinGadgets[5],BackupWinWnd,0,(GA_Disabled),FALSE,(TAG_END));
  243.                         GT_SetGadgetAttrs(BackupWinGadgets[8],BackupWinWnd,0,(GA_Disabled),FALSE,(TAG_END));
  244.                         
  245.                         break;
  246.                         
  247.                         case 1: /* Extract */
  248.                         GT_SetGadgetAttrs(BackupWinGadgets[5],BackupWinWnd,0,(GA_Disabled),TRUE,(TAG_END));
  249.                         GT_SetGadgetAttrs(BackupWinGadgets[8],BackupWinWnd,0,(GA_Disabled),TRUE,(TAG_END));
  250.  
  251.                         break;
  252.                         
  253.                         case 2: /* List */
  254.                         GT_SetGadgetAttrs(BackupWinGadgets[1],BackupWinWnd,0,(GA_Disabled),TRUE,(TAG_END));
  255.                         break;
  256.                         
  257.                         case 3: /* Statistic */
  258.                         GT_SetGadgetAttrs(BackupWinGadgets[5],BackupWinWnd,0,(GA_Disabled),FALSE,(TAG_END));
  259.                         GT_SetGadgetAttrs(BackupWinGadgets[4],BackupWinWnd,0,(GA_Disabled),TRUE,(TAG_END));
  260.                         break;
  261.                     }    
  262.                             
  263.                     break;
  264.                     case GD_Delete:
  265.                     if (FLG_DeleteFiles)
  266.                         FLG_DeleteFiles=FALSE;
  267.                     else    FLG_DeleteFiles=TRUE;
  268.                     break;
  269.                     
  270.                     case GD_Recurs:
  271.                     if (FLG_Recursive)
  272.                         FLG_Recursive=FALSE;
  273.                     else    FLG_Recursive=TRUE;
  274.                     break;
  275.                     
  276.                     case GD_Verbose:
  277.                     if (FLG_Verbose)
  278.                         FLG_Verbose=FALSE;
  279.                     else    FLG_Verbose=TRUE;
  280.                     break;
  281.                     
  282.                     case GD_Ask:
  283.                     if (FLG_AskDisks)
  284.                         FLG_AskDisks=TRUE;
  285.                     else    FLG_AskDisks=FALSE;
  286.                     break;
  287.                     
  288.                     case GD_NewAr:
  289.                     if (FLG_NewArchive)
  290.                         FLG_NewArchive=FALSE;
  291.                     else    FLG_NewArchive=TRUE;
  292.                     break;
  293.                     
  294.                     case GD_Size:
  295.                     FileSize = (((struct StringInfo *)PressedGad->SpecialInfo)->LongInt);
  296.                     break;
  297.                     
  298.                     case GD_GO:
  299.  
  300.                     stccpy(CMDLine,"SkBackup ",256);
  301.                         stccpy(&CMDLine[strlen(CMDLine)],"-b",256-strlen(CMDLine));
  302.                     if(FLG_DeleteFiles&&(ActualCMD!=2)&&(ActualCMD!=3))
  303.                         stccpy(&CMDLine[strlen(CMDLine)],"d",256-strlen(CMDLine));
  304.                     if(FLG_Recursive&&(ActualCMD!=2)&&(ActualCMD!=3))
  305.                         stccpy(&CMDLine[strlen(CMDLine)],"r",256-strlen(CMDLine));
  306.                     if(FLG_AskDisks&&(ActualCMD!=3))
  307.                         stccpy(&CMDLine[strlen(CMDLine)],"k",256-strlen(CMDLine));
  308.                     if(FLG_NewArchive&&(ActualCMD==0))
  309.                         stccpy(&CMDLine[strlen(CMDLine)],"n",256-strlen(CMDLine));
  310.                     if(FLG_Verbose)
  311.                         stccpy(&CMDLine[strlen(CMDLine)],"v",256-strlen(CMDLine));
  312.                     stccpy(&CMDLine[strlen(CMDLine)]," ",256-strlen(CMDLine));
  313.                     stccpy(&CMDLine[strlen(CMDLine)],&Commands[ActualCMD],2);
  314.                     if (ActualCMD!=3)
  315.                         stccpy(&CMDLine[strlen(CMDLine)]," \"",256-strlen(CMDLine));
  316.                     
  317.                     if(ActualCMD!=3)
  318.                     {                                        
  319.                        if (FileReq = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
  320.                                 ASL_TopEdge,50,
  321.                                 ASL_LeftEdge,200,
  322.                                 ASL_Hail,(ULONG)"Choose File",
  323.                                 ASL_Dir,(ULONG)"",
  324.                         ASL_File,(ULONG)"Stuffs",
  325.                                     ASL_Pattern,(ULONG)"~(.info)",
  326.                                 ASL_FuncFlags,FILF_PATGAD,
  327.                                 ASL_Window,BackupWinWnd,
  328.                                 TAG_DONE))
  329.                            {
  330.                                 if (AslRequest(FileReq,0L))
  331.                                 {
  332.                             stccpy(&CMDLine[strlen(CMDLine)],FileReq->rf_Dir,256-strlen(CMDLine));
  333.                             stccpy(&CMDLine[strlen(CMDLine)],FileReq->rf_File,256-strlen(CMDLine));
  334.                             stccpy(&CMDLine[strlen(CMDLine)],"\"",256-strlen(CMDLine));
  335.                         }
  336.                         else
  337.                         {
  338.                             EasyRequest(BackupWinWnd,&WrongSel,0,0,0);
  339.                             break;
  340.                         }
  341.                        }
  342.                     }
  343.                     
  344.                     stccpy(&CMDLine[strlen(CMDLine)]," ",256-strlen(CMDLine));
  345.                     if (ActualCMD!=1)
  346.                        stci_d(&CMDLine[strlen(CMDLine)],FileSize);
  347.                     if((ActualCMD!=1)&&(ActualCMD!=2))
  348.                     {
  349.                        stccpy(&CMDLine[strlen(CMDLine)]," \"",256-strlen(CMDLine));
  350.                           if (FileReq = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
  351.                                 ASL_TopEdge,50,
  352.                                 ASL_LeftEdge,200,
  353.                                 ASL_Hail,(ULONG)"Choose Directory to backup",
  354.                                 ASL_Dir,(ULONG)"",
  355.                                     ASL_Pattern,(ULONG)"~(.info)",
  356.                                 ASL_FuncFlags,FILF_PATGAD,
  357.                         ASL_ExtFlags1,FIL1F_NOFILES,
  358.                                 ASL_Window,BackupWinWnd,
  359.                                 TAG_DONE))
  360.                            {
  361.                                 if (AslRequest(FileReq,0L))
  362.                         {
  363.                             stccpy(&CMDLine[strlen(CMDLine)],FileReq->rf_Dir,256-strlen(CMDLine));
  364.                             stccpy(&CMDLine[strlen(CMDLine)],"\"",256-strlen(CMDLine));
  365.                         }
  366.                         else
  367.                         {
  368.                             EasyRequest(BackupWinWnd,&WrongSel,0,0,0);
  369.                             break;
  370.                         }
  371.                        }
  372.                     }                    
  373.                     
  374.                     else if (ActualCMD==1)
  375.                     {
  376.                           if (FileReq = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
  377.                                 ASL_TopEdge,50,
  378.                                 ASL_LeftEdge,200,
  379.                                 ASL_Hail,(ULONG)"Choose where to Extract",
  380.                                 ASL_Dir,(ULONG)"",
  381.                                     ASL_Pattern,(ULONG)"~(.info)",
  382.                                 ASL_FuncFlags,FILF_PATGAD,
  383.                         ASL_ExtFlags1,FIL1F_NOFILES,
  384.                                 ASL_Window,BackupWinWnd,
  385.                                 TAG_DONE))
  386.                            {
  387.                                 if (AslRequest(FileReq,0L))
  388.                         {
  389.                             ExtractDir=Lock(FileReq->rf_Dir,ACCESS_READ);
  390.                             CurrentDir(ExtractDir);
  391.                         }
  392.                         
  393.                         else
  394.                         {
  395.                             EasyRequest(BackupWinWnd,&WrongSel,0,0,0);
  396.                             break;
  397.                         }
  398.                        }
  399.                     }
  400.                     
  401.                     /* printf("%s\n",CMDLine); */
  402.  
  403.                     stags[0].ti_Tag = SYS_Input;
  404.                      stags[0].ti_Data = Input();
  405.                     stags[1].ti_Tag = SYS_Output;
  406.                         stags[1].ti_Data = Output();
  407.                         stags[3].ti_Tag = TAG_DONE;
  408.                                          
  409.                     System(CMDLine,stags);
  410.                     UnLock(ExtractDir);
  411.                     printf("\nClick on the close gadget to return!\n");
  412.  
  413.                     break;
  414.                     
  415.                     case GD_Gadget70:
  416.                     EasyRequest(BackupWinWnd,&AboutRequest,0,0,0);
  417.                     break;
  418.                     }
  419.                 break;
  420.         }
  421.     }
  422. }
  423. }
  424.  
  425. int OpenBackupWinWindow(void)
  426. {
  427.     struct NewGadget    ng;
  428.     struct Gadget    *g;
  429.     UWORD        lc, tc;
  430.     UWORD        offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  431.  
  432.     if ( ! ( g = CreateContext( &BackupWinGList )))
  433.         return( 1L );
  434.  
  435.     for( lc = 0, tc = 0; lc < BackupWin_CNT; lc++ ) {
  436.  
  437.         CopyMem((char * )&BackupWinNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  438.  
  439.         ng.ng_VisualInfo = VisualInfo;
  440.         ng.ng_TextAttr   = &topaz8;
  441.         ng.ng_LeftEdge  += offx;
  442.         ng.ng_TopEdge   += offy;
  443.  
  444.         BackupWinGadgets[ lc ] = g = CreateGadgetA((ULONG)BackupWinGTypes[ lc ], g, &ng, ( struct TagItem * )&BackupWinGTags[ tc ] );
  445.  
  446.         while( BackupWinGTags[ tc ] ) tc += 2;
  447.         tc++;
  448.  
  449.         if ( NOT g )
  450.             return( 2L );
  451.     }
  452.  
  453.     if ( ! ( BackupWinWnd = OpenWindowTags( NULL,
  454.                 WA_Left,    BackupWinLeft,
  455.                 WA_Top,        BackupWinTop,
  456.                 WA_Width,    BackupWinWidth,
  457.                 WA_Height,    BackupWinHeight + offy,
  458.                 WA_IDCMP,    CYCLEIDCMP|CHECKBOXIDCMP|INTEGERIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  459.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  460.                 WA_Gadgets,    BackupWinGList,
  461.                 WA_Title,    BackupWinWdt,
  462.                 WA_ScreenTitle,    "Original program ©1994 by Alessandro Pozzoli",
  463.                 TAG_DONE )))
  464.     return(4L);
  465.  
  466.     GT_RefreshWindow(BackupWinWnd, NULL);
  467.  
  468.     return(0L);
  469. }
  470.  
  471. void CloseBackupWinWindow( void )
  472. {
  473.     if ( BackupWinWnd        ) {
  474.         CloseWindow( BackupWinWnd );
  475.         BackupWinWnd = NULL;
  476.     }
  477.  
  478.     if ( BackupWinGList      ) {
  479.         FreeGadgets( BackupWinGList );
  480.         BackupWinGList = NULL;
  481.     }
  482. }
  483.  
  484.  
  485. void main()
  486. {
  487.  
  488.     if(!SetupScreen())
  489.     {
  490.         if(!OpenBackupWinWindow())
  491.         {
  492.             HandleBackupWinIDCMP();
  493.             CloseBackupWinWindow();
  494.             CloseDownScreen();
  495.         }
  496.         else printf("cannot open window!\n");
  497.     }
  498.     else printf("cannot open screen!\n");
  499. }
  500.